#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);



    QRegExp rxlen("(\\d+)\\s*(cm|inch)");
    int pos = rxlen.indexIn("Length: 189cm");
    if (pos > -1)
    {
        QString value = rxlen.cap(1); // "189"
        QString unit = rxlen.cap(2);  // "cm"
        ui->textEdit->insertPlainText(value);
        ui->textEdit->insertPlainText(unit);
    }


//    QRegExp rx("(\\d+)(?:\\s*)(cm|inch(?:es)?)");
//    int pos = rx.indexIn("Length: 36 inches");
//    QStringList list = rx.capturedTexts();
//    // list is now ("36 inches", "36", "inches")

    QRegExp rx2("blue");
    bool ret = rx2.exactMatch("blue");
    qDebug()<<ret << " " <<rx2.matchedLength();
    ret = rx2.exactMatch("bluetooth");
    qDebug()<<ret << " " <<rx2.matchedLength();
    ret = rx2.exactMatch("bluABC");
    qDebug()<<ret << " " <<rx2.matchedLength();
    ret = rx2.exactMatch("red_blue");
    qDebug()<<ret << " " <<rx2.matchedLength();
}

MainWindow::~MainWindow()
{
    delete ui;
}
